import React from "react";
const Index = () => {
    // 状态
    const listRef = React.useRef(null)
    const [list, setList] = React.useState([])
    const [finished, setFinished] = React.useState(false)
    const [LoginUser, setLoginUser] = React.useState(React.$Cookie.load('LoginUser') ? React.$Cookie.load('LoginUser') : {})
    const navigate = React.$Router.useNavigate()
    let data = []
    React.useEffect(() => {
        // let LoginUser = React.$Cookie.load('LoginUser') ? React.$Cookie.load('LoginUser') : {}

        // setLoginUser(LoginUser)

    },[])
    const ProductData = async () =>
    {

        let result = await React.$Api.GetCollect({busid:LoginUser.id,})
        if(result)
        {
            if(result.code === 1)
            {
                data = data.concat(result.data)
                setList(data)
            }else{
                React.$Vant.Toast.info(result.msg)
                setFinished(true)
                return false
            }
        }
    }

    const onBack = () => {
        navigate("/user/base/index");
    };
    const Items = () => {
        return list.map((item, index) => {
            return (
                <li key={index}>
                    <React.$Router.NavLink to={`/product/product/info?pid=${item.products.id}`}>
                        <img src={item.products.cover_cdn} alt="" />
                        <p>{item.products.name}</p>
                        <span>{item.products.rent_price}</span>
                    </React.$Router.NavLink>
                </li>
            );
        });
    };
    const load=()=>{
        ProductData()
        setFinished(true)
    }
    return (
        <>
            {/* 导航栏 */}
            <React.$Vant.Sticky>
                <React.$Vant.NavBar title="收藏列表" onClickLeft={onBack} zIndex="10" />
            </React.$Vant.Sticky>
            <React.$Vant.List
                ref={listRef}
                onLoad={load}
                offset={5}
                finished={finished}
            >
                <div className="left_kuangs">
                    <ul>
                        <Items />
                    </ul>
                </div>
            </React.$Vant.List>
        </>
    );
};
export default Index;
